import { Toolkit } from "../Framework/scripts/Toolkit";
import Watcher from "../Framework/scripts/Watcher";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Top extends cc.Component {


    @property(cc.Sprite)
    scoreProgress: cc.Sprite = null;
    @property(cc.Label)
    score:cc.Label = null;
    @property([cc.Sprite])
    star_sprites:cc.Sprite[] = [];
    @property(cc.SpriteFrame)
    star_light_sf:cc.SpriteFrame;

    public static readonly CHANGE_SCORE = 'score-change';

    onLoad() {
        this.scoreProgress.fillRange = 0;
        Watcher.on(Top.CHANGE_SCORE, this, (cur: number, max: number) => {
            let f = Toolkit.Clamp(cur * 1.0 / max, 0.0, 1.0);
            
            //进度条
            this.scoreProgress.fillRange = f;

            //分数显示
            this.score.string = cur.toFixed(0);

            //星星
            f >= 0.41 && (this.star_sprites[0].spriteFrame=this.star_light_sf);
            f >= 0.75 && (this.star_sprites[1].spriteFrame=this.star_light_sf);
            f >= 0.99 && (this.star_sprites[2].spriteFrame=this.star_light_sf);
        });
    }

}
